package com.house.rent.ui.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.base.lib.mvp.present.BasePresenter;
import com.base.lib.util.MaterialDialogUtils;
import com.base.lib.util.ScreenManager;
import com.house.rent.App;
import com.house.rent.R;
import com.house.rent.entity.UserEntity;

import butterknife.BindView;
import butterknife.OnClick;

public class PersonInfoActivity extends BaseActivity {

    @BindView(R.id.tv_user_name)
    TextView tvName;
    @BindView(R.id.tv_user_email)
    TextView tvEmail;

    public static void start(Context context) {
        Intent starter = new Intent(context, PersonInfoActivity.class);
        context.startActivity(starter);
    }

    @Override
    protected void initTop() {
        setTitle("个人资料");
    }

    @Override
    protected int getLayoutResId() {
        return R.layout.activity_person_info;
    }

    @Override
    protected void initView(Bundle savedInstanceState) {
        UserEntity userEntity = App.getInstance().getUserEntity();

        tvName.setText(userEntity.getNickName());
        tvEmail.setText(userEntity.getMobile());
    }

    @Override
    protected void initListeners() {

    }

    @Override
    protected BasePresenter initPresenter() {
        return null;
    }

    @Override
    protected void initData() {

    }


    /**
     * 退出登录操作
     */
    private void logout() {
        //清空session，本地登录状态
        App.getInstance().logout();
        ScreenManager.getInstance().popActivity(MainActivity.class);
        LoginActivity.start(mContext);
        finish();

    }

    @OnClick({R.id.layout_user_idCard})
    public void onViewIdCard(View view) {
        IdCardDetailActivity.start(mContext, App.getInstance().getUserEntity().getId());
    }

    @OnClick({R.id.layout_logout})
    public void onViewClicked(View view) {
        MaterialDialogUtils.show(mContext, "是否退出？",
                (dialog, which) -> logout());
    }
}
